package com.gxc.mongo.controller;

import com.gxc.mongo.entity.Spit;
import com.gxc.mongo.service.SpitService;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * SpitController.
 *
 * @author 宫新程
 * @since 2019/1/16 4:58 PM
 */
@RestController
@RequestMapping("/spit")
public class SpitController {

  @Resource private SpitService spitService;

  /** 查询全部. */
  @GetMapping
  public List<Spit> findAll() {
    return this.spitService.findAll();
  }

  /** 查询全部. */
  @GetMapping("/{pageNum}/{pageSize}")
  public Page<Spit> findPage(@PathVariable Integer pageNum, @PathVariable Integer pageSize) {
    return this.spitService.findAll(pageNum, pageSize);
  }

  /** 根据ID查询. */
  @GetMapping("/{id}")
  public Spit findById(@PathVariable String id) {
    return this.spitService.findById(id);
  }

  /** 保存. */
  @PostMapping
  public Boolean save(@RequestBody Spit spit) {
    this.spitService.save(spit);
    return true;
  }

  /** 更新. */
  @PutMapping
  public Boolean update(@RequestBody Spit spit) {
    this.spitService.update(spit);
    return true;
  }

  /** 删除. */
  @DeleteMapping("/{id}")
  public Boolean delete(@PathVariable String id) {
    this.spitService.deleteById(id);
    return true;
  }

  @GetMapping("/test")
  public List<Spit> findVisitsGl1000() {
    return this.spitService.findVisitsGl1000();
  }
}
